package com.gl.rent;

import cn.hutool.core.convert.Convert;
import com.gl.common.util.SecurityUtils;
import com.haixiaoke.saas.repository.core.AjaxResult;
import com.haixiaoke.saas.repository.core.BaseController;
import com.haixiaoke.saas.repository.core.page.TableDataInfo;
import com.haixiaoke.saas.repository.pojo.ApartmentChargeItem;
import com.haixiaoke.saas.repository.service.IApartmentChargeItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公寓收费项目Controller
 *
 * @author qixi
 * @date 2023-06-13
 */
@RestController
@RequestMapping("/business/chargeItem")
public class ApartmentChargeItemController extends BaseController {
    @Autowired
    private IApartmentChargeItemService apartmentChargeItemService;

    /**
     * 查询公寓收费项目列表
     */
    // @PreAuthorize("@ss.hasPermi('business:chargeItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApartmentChargeItem apartmentChargeItem) {
        startPage();
        List<ApartmentChargeItem> list = apartmentChargeItemService.selectApartmentChargeItemList(apartmentChargeItem);
        return getDataTable(list);
    }


    /**
     * 获取公寓收费项目详细信息
     */
    // @PreAuthorize("@ss.hasPermi('business:chargeItem:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") Long itemId) {
        return success(apartmentChargeItemService.selectApartmentChargeItemByItemId(itemId));
    }

    /**
     * 新增公寓收费项目
     */
    // @PreAuthorize("@ss.hasPermi('business:chargeItem:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ApartmentChargeItem apartmentChargeItem) {

        //填写创建人
        String id = Convert.toStr(SecurityUtils.getLoginUserId());
        apartmentChargeItem.setCreateBy(id);

        apartmentChargeItem.setOrgId(0L);
        return toAjax(apartmentChargeItemService.insertApartmentChargeItem(apartmentChargeItem));
    }

    /**
     * 修改公寓收费项目
     */
    // @PreAuthorize("@ss.hasPermi('business:chargeItem:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ApartmentChargeItem apartmentChargeItem) {
        return toAjax(apartmentChargeItemService.updateApartmentChargeItem(apartmentChargeItem));
    }

    /**
     * 删除公寓收费项目
     */
    // @PreAuthorize("@ss.hasPermi('business:chargeItem:remove')")
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds) {
        return toAjax(apartmentChargeItemService.deleteApartmentChargeItemByItemIds(itemIds));
    }
}
